package com.sky.service.impl;

import com.sky.entity.SearchHistroy;
import com.sky.mapper.SearchHistoryMapper;
import com.sky.service.SearchHistoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class SearchHistoryServiceImpl implements SearchHistoryService {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private SearchHistoryMapper searchHistoryMapper;

    /**
     * 返回五条最新的历史记录
     * @param id
     * @return
     */
    @Override
    public List<String> searchList(Long id) {

        List<SearchHistroy> list= searchHistoryMapper.select();
        List<String> strings = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            strings.add(list.get(i).getValue()) ;
        }

        return strings;


    }


    /**
     * 用户查询
     * @param
     * @param
     * @return
     */
    @Override
    public List<String> search(String content) {
        List<SearchHistroy> list= searchHistoryMapper.selectByContent(content);
        List<String> strings = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            strings.add(list.get(i).getValue()) ;
        }

        return strings;

    }
}
